package com.gitee.minimalismstyle.fresh.simple.api.model

import com.google.common.base.CaseFormat
import java.math.BigDecimal
import java.time.LocalDate
import java.time.LocalDateTime

class TableColumnSchema{
    var name: String? = null
        set(value) {
            field = value
            fieldName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, value!!)
            if(value.equals("id", true)){
                isPk = true
            }
        }

    var type: String? = null
        set(value) {
            field = value
            if(listOf<String>("int").contains(value)){
                fieldType = "Int"
                fieldFullType = Int::class.java.name
            }else if(listOf<String>("bigint").contains(value)){
                fieldType = "Long"
                fieldFullType = Long::class.java.name
            }else if(listOf<String>("decimal").contains(value)){
                fieldType = "BigDecimal"
                fieldFullType = BigDecimal::class.java.name
            }else if(listOf<String>("date", "date").contains(value)){
                fieldType = "LocalDate"
                fieldFullType = LocalDate::class.java.name
            }else if(listOf<String>("datetime", "date").contains(value)){
                fieldType = "LocalDateTime"
                fieldFullType = LocalDateTime::class.java.name
            }else{
                fieldType = "String"
                fieldFullType = String::class.java.name
            }
        }

    var key: String? = null
        set(value) {
            field = value
            if(listOf<String>("PRI").contains(value)){
                isPk = true
            }
        }

    var comment: String? = null

    var fieldName: String? = null

    var fieldType: String? = null

    var fieldFullType: String? = null

    var isPk: Boolean = false
}
